package com.kingint.web.portal.serve.controller;


import com.kingint.mbg.bas.entity.BasWorkOrderType;
import com.kingint.web.domain.FrontParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.kingint.common.unitedresult.K;
import com.kingint.web.portal.serve.service.SerWorkOrderService;

import java.util.List;


/**
 * @描述：相关工单总表控制类
 * @作者: wxh
 * @日期: 2021-01-08
 */
@RestController
@RequestMapping("/serWorkOrder")
@Api(value = "SerWorkOrderController", description = "相关工单总表")
@CrossOrigin
public class SerWorkOrderController {

    @Autowired
    public SerWorkOrderService serWorkOrderService;


    @ApiOperation(value = "首页获取相关的工单列表信息（待接单，处理中，待确认的）")
    @GetMapping("/getAllWorkOrderList")
    public Object getList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                          @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        Object orderList = serWorkOrderService.getAllWorkOrderList(pageNum, pageSize);
        return K.ok().data(orderList);
    }

    @ApiOperation(value = "首页获取相关的工单列表信息（待接单）")
    @GetMapping("/getWaitWorkOrderList")
    public Object getWaitWorkOrderList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                       @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        Object orderList = serWorkOrderService.getWaitWorkOrderList(pageNum, pageSize);
        return K.ok().data(orderList);
    }


    //获取通知数量，抢单数量，是否打卡
    @ApiOperation(value = "获取通知数量，抢单数量，是否打卡")
    @GetMapping("/getFrontInfoNumber")
    public Object getFrontInfoNumber() {
        return serWorkOrderService.getFrontSomethingNumber();
    }

    //相关首页列表中的工单接单，查询详情等操作

    @ApiOperation(value = "相关首页列表中的工单抢单(报修单，服务单）")
    @PostMapping("/grabOrder")
    public Object grabOrder(@RequestBody FrontParam frontParam) {
        Integer id = serWorkOrderService.grabOrder(frontParam);
        if (id > 0) {
            return K.ok().data(id);
        }
        return K.error();
    }

    @ApiOperation(value = "相关工单确认，回复接口（赶房，群发通知等）")
    @PostMapping("/confirmOrder")
    public Object confirmOrder(@RequestBody FrontParam frontParam) {
        Integer i = serWorkOrderService.confirmOrder(frontParam);
        if (i > 0) {
            return K.ok().data(i);
        }
        return K.error();
    }

    @ApiOperation(value = "首页获取工单列表信息（待审核的，登录人员有权限审核的）")
    @GetMapping("/getWaitHandleOrderList")
    public Object getWaitHandleOrderList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                         @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        Object orderList = serWorkOrderService.getWaitHandleOrderList(pageNum, pageSize);
        return K.ok().data(orderList);
    }

    @ApiOperation(value = "审核工单接口")
    @PostMapping("/examineOrder")
    public Object examineOrder(@RequestBody FrontParam frontParam) {
        Integer i = serWorkOrderService.examineOrder(frontParam);
        if (i > 0) {
            return K.ok().data(i);
        }
        return K.error();
    }

    //所有工单类型
    @ApiOperation(value = "获取工单类型")
    @GetMapping("/getAllWorkType")
    public Object getAllWorkType() {
        List<BasWorkOrderType> list = serWorkOrderService.getAllWorkType();
        return K.ok().data(list);
    }

    @ApiOperation(value = "获取用户所有的工单信息(0,全部，1,待确认，2，处理中，3，审核中，4，完成")
    @GetMapping("/getAllUserBillList")
    public Object getAllUserBillList(@RequestParam(value = "type",defaultValue = "0") Integer type,
                                     @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                     @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        Object orderList = serWorkOrderService.getAllUserBillList(type,pageNum,pageSize);
        return K.ok().data(orderList);
    }
}